package bancosys.tec.persist.uniquevalue.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import jmine.tec.persist.annotation.Alias;

import org.hibernate.annotations.Filter;
import org.hibernate.annotations.Filters;

import bancosys.tec.persist.authorization.annotation.DisplayName;
import bancosys.tec.persist.bussobj.AuthPersistableBusinessObject;
import bancosys.tec.persist.uniquevalue.annotation.UniqueGeneratedValue;

/**
 * Entidade que possui pelo menos um atributo gerado pelo {@link UniqueValueReference}
 * 
 * @author Rafael Volpato
 */
@Entity
@Alias("AENUGV")
@Table(name = "A_ENTITY_W_UGV")
@Filters({ @Filter(name = "authFilter", condition = "auth = :auth") })
@DisplayName("Entidade que possui pelo menos um atributo gerado pelo UniqueValueReference")
public class AuthorizableEntityWithUniqueValue extends AuthPersistableBusinessObject {

    private Long id;

    private Long generatedValue;

    private String mnemonico;

    /**
     * @return the id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return this.id;
    }

    /**
     * Set the id
     * 
     * @param id id
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the generatedValue
     */
    @Column(name = "UGV", nullable = false, updatable = false)
    public Long getGeneratedValue() {
        return this.generatedValue;
    }

    /**
     * @param generatedValue the generatedValue to set
     */
    @UniqueGeneratedValue("UVR1")
    public void setGeneratedValue(Long generatedValue) {
        if (this.generatedValue != null && !this.generatedValue.equals(generatedValue)) {
            throw new IllegalStateException("o campo generatedValue não pode ser alterado!");
        }
        this.generatedValue = generatedValue;
    }

    /**
     * @return the mnemonico
     */
    @Column(name = "MNE")
    public String getMnemonico() {
        return this.mnemonico;
    }

    /**
     * @param mnemonico the mnemonico to set
     */
    public void setMnemonico(String mnemonico) {
        this.mnemonico = mnemonico;
    }
}
